package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.PickInfoListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class PickInfoListAdapter extends BaseRecycleAdapter<PickInfoListEntity> {

    public PickInfoListAdapter(Context context, List<PickInfoListEntity> datas) {
        super(context, R.layout.item_pick_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PickInfoListEntity goodsInfoEntity3) {
        holder.setBinding(BR.viewModel, goodsInfoEntity3);

        TextView tvAddr = holder.itemView.findViewById(R.id.tv_addr);
        LinearLayout lineTime = holder.itemView.findViewById(R.id.line_time);
        TextView tvType2 = holder.itemView.findViewById(R.id.tv_type2);
        ImageView imgTab = holder.itemView.findViewById(R.id.img_tab);

        imgTab.setVisibility(View.VISIBLE);

        long now = System.currentTimeMillis();
        if (goodsInfoEntity3.getEndTime() != null && !"".equals(goodsInfoEntity3.getEndTime())) {
            if (Long.valueOf(DateUtils.dateTo13Timestam4(goodsInfoEntity3.getEndTime())) < now) {
                imgTab.setBackground(context.getResources().getDrawable(R.mipmap.icn_yjs));
                lineTime.setVisibility(View.GONE);
            } else {
                imgTab.setBackground(context.getResources().getDrawable(R.mipmap.icn_zbz));
                if(goodsInfoEntity3.getEndTimeStr() != null && !"".equals(goodsInfoEntity3.getEndTimeStr())){
                    lineTime.setVisibility(View.VISIBLE);
                }
            }
        } else {
            imgTab.setVisibility(View.GONE);
            lineTime.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(goodsInfoEntity3.getAreaName())) {
            tvAddr.setText(goodsInfoEntity3.getAreaName());
        } else if (!TextUtils.isEmpty(goodsInfoEntity3.getCityName())) {
            tvAddr.setText(goodsInfoEntity3.getCityName());
        }

        /*if(null!= goodsInfoEntity3.getState()){
            if(goodsInfoEntity3.getState().equals("已结束")){
                tvtime.setText("已结束");
                tvtime.setVisibility(View.VISIBLE);
                endTime.setVisibility(View.GONE);
            }else{
                if(!TextUtils.isEmpty(goodsInfoEntity3.getEndTime())){
                    long end = Long.parseLong(goodsInfoEntity3.getEndTime());
                    if(end - System.currentTimeMillis()>0){
                        long time = (end - System.currentTimeMillis()) / 1000 / 60 / 60;
                        endTime.setText(time+"小时");

                        tvtime.setText("距截止还有  ");
                        tvtime.setVisibility(View.VISIBLE);
                        endTime.setVisibility(View.VISIBLE);
                    }else{
                        endTime.setVisibility(View.GONE);
                        tvtime.setVisibility(View.GONE);
                    }
                }
            }
        }else{
            endTime.setVisibility(View.GONE);
            tvtime.setVisibility(View.GONE);
        }*/

        if (!TextUtils.isEmpty(goodsInfoEntity3.getType())) {
            tvType2.setText("【" + goodsInfoEntity3.getType() + "】");
        } else {
            tvType2.setText("");
        }

    }
}
